package com.zenithsun.web;

public class ResponseGenerator {
    private static final String MESSAGE_SUCCESS="请求成功";
    private static final String MESSAGE_FAIL="请求失败";
    private static final String MESSAGE_UNAUTHORIZED="权限不足";
    //成功
    public static ResponseEntity genSuccessResult() {
        return new ResponseEntity()
                .setCode(ResultCodeEnum.SUCCESS)
                .setMessage(MESSAGE_SUCCESS);
    }

    public static <T> ResponseEntity<T> genSuccessResult(T data) {
        return new ResponseEntity()
                .setCode(ResultCodeEnum.SUCCESS)
                .setMessage(MESSAGE_SUCCESS)
                .setData(data);
    }

    public static ResponseEntity genFailResult(String message) {
        return new ResponseEntity()
                .setCode(ResultCodeEnum.FAIL)
                .setMessage( message == null ? MESSAGE_FAIL : message);
    }

    public static ResponseEntity genUnauthorizedResult() {
        return new ResponseEntity()
                .setCode(ResultCodeEnum.UNAUTHORIZED)
                .setMessage(MESSAGE_UNAUTHORIZED);
    }
}

